#ifndef SGMDEV_PD_H
#define SGMDEV_PD_H

#include "common.h"

/************************* GENERAL ***************************/
#define SGM_DEV_VID                         0x377e
#define SGM_41620_PID                       0x6600
#define SGM_41620_DID                       0x0001
#define SGM_795_PID                         0x0795
#define SGM_795_DID                         0x1020
/************************* GENERAL ***************************/

/************************* SGM41620 **************************/
#define SGM41620_REG_ANACTRL1                   0x90
    #define SGM41620_REG_ANACTRL1_VCONN_DISC    (1 << 5)
#define SGM41620_REG_VCONNOCP                   0x93
#define SGM41620_REG_ANASTS                     0x97
    #define SGM41620_REG_ANASTS_VBUS_80         (1 << 1)
#define SGM41620_REG_ANAINT                     0x98
    #define SGM41620_REG_ANAINT_HRST            (1 << 7)
    #define SGM41620_REG_ANAINT_RADETACH        (1 << 5)
    #define SGM41620_REG_ANAINT_CCOVP           (1 << 2)
    #define SGM41620_REG_ANAINT_VBUS_80         (1 << 1)
    #define SGM41620_REG_ANAINT_WAKEUP          (1 << 0)
#define SGM41620_REG_ANAMASK                    0x99
#define SGM41620_REG_IDLE_CTRL                  0x9B
    #define SGM41620_REG_CK_300K_SEL            (1<<7)
    #define SGM41620_REG_SHIPPING_OFF           (1<<5)
    #define SGM41620_REG_ENEXTMSG               (1<<4)
    #define SGM41620_REG_AUTOIDLE_EN            (1<<3)
    #define SGM41620_REG_IDLETIME               GENMASK(2, 0) // (val * 2 + 1) * 6.4ms
    #define SGM41620_REG_IDLE_SET(ck300, ship_dis, auto_idle, tout) \
            ((ck300 << 7) | (ship_dis << 5) | (auto_idle << 3) | (tout & 0x07))
#define SGM41620_REG_SWRESET                    0xA0
#define SGM41620_REG_DRP_TOGGLE_CYCLE           0xA2
#define SGM41620_REG_DRP_DUTY_CTRL0             0xA3
#define SGM41620_REG_DRP_DUTY_CTRL1             0xA4
#define SGM41620_REG_WDT                        0xA5
    #define SGM41620_REG_WDT_TIMER_RST          (1 << 7)
    #define SGM41620_REG_WDT_TIMER              GENMASK(2, 0)
/************************* SGM41620 **************************/

/************************* SGM795 ****************************/
#define SGM795_REG_SGCTL                        0x90
    #define SGM795_REG_SGCTL_DISVCONNOV         (1 << 7)
    #define SGM795_REG_SGCTL_VCONNOTPEN         (1 << 6)
    #define SGM795_REG_SGCTL_LPRPRD             (1 << 4)
    #define SGM795_REG_SGCTL_LPEN               (1 << 3)
    #define SGM795_REG_SGCTL_VBUS_DETEN         (1 << 1)
#define SGM795_REG_VCONNOCP                     0x93
    #define SGM795_REG_VCONNOCP_CL              GENMASK(7, 5)
#define SGM795_REG_SGSTS                        0x97
    #define SGM795_REG_SGSTS_OTP                (1 << 5)
    #define SGM795_REG_SGSTS_VBUS55             (1 << 4)
    #define SGM795_REG_SGSTS_VBUS475            (1 << 3)
    #define SGM795_REG_SGSTS_VSAFE0V            (1 << 1)
#define SGM795_REG_SGINT                        0x98
    #define SGM795_REG_SGINT_VCONNOTP           (1 << 6)
    #define SGM795_REG_SGINT_RADETACH           (1 << 5)
    #define SGM795_REG_SGINT_VBUS55             (1 << 4)
    #define SGM795_REG_SGINT_VBUS475            (1 << 3)
    #define SGM795_REG_SGINT_VCONNOV            (1 << 2)
    #define SGM795_REG_SGINT_VSAFE0V            (1 << 1)
    #define SGM795_REG_SGINT_WAKEUP             (1 << 0)
#define SGM795_REG_SGINT_MASK                   0x99
#define SGM795_REG_SHUTDOWN                     0x9B
    #define SGM795_REG_SHUTDOWN_OFF             (1 << 5)
#define SGM795_REG_WAKEUP                       0x9F
    #define SGM795_REG_WAKEUP_WAKEUP            (1 << 7)
#define SGM795_REG_SWRESET                      0xA0
#define SGM795_REG_DRP_TOGGLE_CYCLE             0xA2
#define SGM795_REG_DRP_DUTY_CTRL0               0xA3
#define SGM795_REG_DRP_DUTY_CTRL1               0xA4
/************************* SGM595 ****************************/

int sgmdev_check_revision(void);
int sgmdev_command(uint8_t cmd);
void sgmdev_pd_work_handle(void);
void tcpc_device_wrap_ops(void);

#endif /* #ifndef SGM41620_H */
